package cn.hx.mall.order.controller;

import cn.hx.mall.order.entity.OrderReturnReason;
import cn.hx.mall.order.service.OrderReturnReasonService;
import cn.hx.mall.permissions.entity.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


/**
 * 退货原因表(OrderReturnReason)表控制层
 *
 * @author makejava
 * @since 2022-11-02 17:57:09
 */
@Controller
@RequestMapping("order")
public class OrderReturnReasonController {
    @Autowired
    private OrderReturnReasonService orderReturnReasonService;
    @GetMapping("/returnReasonList")
    public String returnReasonList(Model model, Page page){
        OrderReturnReason orr = new OrderReturnReason();
        orr.setName(page.getSearch());
        List<OrderReturnReason> orderReturnReasons = orderReturnReasonService.queryAllByLimit(orr,page.getPage(), page.getLimit());
        Page page1 = orderReturnReasonService.getPageInfo(page);
        model.addAttribute("orderReturnReasonList", orderReturnReasons);
        model.addAttribute("pageInfo", page1);
        return "order/returnReasonList";
    }

    @GetMapping("returnReasonListDelete/{id}")
    public String returnReasonListDelete(@PathVariable Long id){
        orderReturnReasonService.deleteById(id);
        return "redirect:/order/returnReasonList";
    }
    @GetMapping("/returnReasonListUpdate/{id}")
    public String returnReasonListUpdate(@PathVariable Long id,Model model){
        OrderReturnReason orderReturnReason = orderReturnReasonService.queryById(id);
        model.addAttribute("o",orderReturnReason);
        return "order/returnReasonListUpdate";
    }
    @PostMapping("/returnReasonListUpdate/{id}")
    public String returnReasonListUpdate(OrderReturnReason orderReturnReason){
        orderReturnReasonService.update(orderReturnReason);
        return "redirect:/order/returnReasonList";
    }
    @PostMapping("/returnReasonListAdd")
    public String returnReasonListAdd(OrderReturnReason orderReturnReason){
        orderReturnReasonService.insert(orderReturnReason);
        return "redirect:/order/returnReasonList";
    }
}
















